<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/orderset.css">
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <!-- 引入样式 -->
    <!--    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">-->
    <!-- 引入组件库 -->
    <!--    <script src="https://unpkg.com/element-ui/lib/index.js"></script>-->

    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            padding-left: 7px;
            padding-right: 20px;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统管理<small>用户管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统管理</el-breadcrumb-item>
            <el-breadcrumb-item>用户管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <div class="block">

                    <el-input placeholder="用户名" v-model="pagination.queryString" style="width: 200px;"
                              class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                    <el-button @click="findPage()" class="dalfBut">查询</el-button>
                    <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                </div>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="username" label="用户名" align="center"></el-table-column>
                <el-table-column prop="telephone" label="手机号" align="center"></el-table-column>

                <el-table-column prop="gender" label="适用性别" align="center"></el-table-column>
                <el-table-column prop="birthday" label="出生日期" align="center"></el-table-column>
                <el-table-column prop="station" label="禁用状态" align="center"></el-table-column>
                <el-table-column prop="remark" label="说明" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button @click="handleEditUser(scope.row)" type="primary" size="mini">编辑</el-button>
                        <el-button @click="handleDelete(scope.row)" type="danger" size="mini">删除</el-button>
                    </template>

                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增用户" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="用户名" prop="username">
                                                <el-input v-model="formData.username"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="密码" prop="password">
                                                <el-input v-model="formData.password"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp性别&nbsp&nbsp
                                        <el-select v-model="gender" clearable placeholder="性别">
                                            <el-option
                                                    v-for="item in selectGender"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                            </el-option>
                                        </el-select>
                                            </el-col>
                                        <el-col span="12">
                                            &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp状态&nbsp&nbsp
                                        <el-select v-model="station" clearable placeholder="状态">
                                            <el-option
                                                    v-for="item in selectStation"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                            </el-option>
                                        </el-select>
                                        </el-col>
                                    </el-row>
                                        <el-row>
                                            <el-col>&nbsp</el-col>
                                        </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="手机号码" prop="telephone">
                                                <el-input v-model="formData.telephone"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期" prop="birthday">
                                                <el-col :span="20">
                                                    <el-date-picker
                                                            type="date"
                                                            placeholder="选择日期" v-model="formData.birthday"
                                                            style="width: 100%;"/>
                                                </el-col>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="20">
                                            <el-form-item label="说明" prop="remark">
                                                <el-input type="textarea" v-model="formData.remark"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="角色信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>角色名称</th>
                                            <th>关键词</th>
                                            <th>角色说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td width="90">
                                                <input :id="c.id" v-model="roleIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td width="115"><label :for="c.id">{{c.name}}</label></td>
                                            <td width="180"><label :for="c.id">{{c.keyword}}</label></td>
                                            <td><label :for="c.id">{{c.description}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!--编辑标签弹层-->
            <div class="add-form">
                <el-dialog title="编辑用户" :visible.sync="editDialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataEditForm" :model="formData" :rules="rule" label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="用户名" prop="username">
                                                <el-input v-model="formData.username"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="密码" prop="password">
                                                <el-input v-model="formData.password"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp性别&nbsp&nbsp
                                            <el-select v-model="gender" clearable placeholder="性别">
                                                <el-option
                                                        v-for="item in selectGender"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value">
                                                </el-option>
                                            </el-select>
                                        </el-col>
                                        <el-col span="12">
                                            &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp状态&nbsp&nbsp
                                            <el-select v-model="station" clearable placeholder="状态">
                                                <el-option
                                                        v-for="item in selectStation"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value">
                                                </el-option>
                                            </el-select>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col>&nbsp</el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="手机号码" prop="telephone">
                                                <el-input v-model="formData.telephone"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期" prop="birthday">
                                                <el-col :span="20">
                                                    <el-date-picker
                                                            type="date"
                                                            placeholder="选择日期" v-model="formData.birthday"
                                                            style="width: 100%;"/>
                                                </el-col>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="20">
                                            <el-form-item label="说明" prop="remark">
                                                <el-input type="textarea" v-model="formData.remark"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="角色信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>角色名称</th>
                                            <th>关键词</th>
                                            <th>角色说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td width="90">
                                                <input :id="c.id" v-model="roleIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td width="115"><label :for="c.id">{{c.name}}</label></td>
                                            <td width="180"><label :for="c.id">{{c.keyword}}</label></td>
                                            <td><label :for="c.id">{{c.description}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="editDialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleUpdate()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            // orderStatus:null,
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//添加表单窗口中检查组列表数据
            roleIds: [],//添加表单窗口中套餐复选框对应id
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            editDialogFormVisible: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                phoneNum: [{required: true, message: '手机号为必填项', trigger: 'blur'}],
                username: [{required: true, message: '用户名必填项', trigger: 'blur'}],
                password: [{required: true, message: '密码为必填项', trigger: 'blur'}],
            },
            rule: {//校验规则
                phoneNum: [{required: true, message: '手机号为必填项', trigger: 'blur'}],
                username: [{required: true, message: '用户名必填项', trigger: 'blur'}],
            },


            //预约类型下拉框
            selectGender: [
                {
                    label:'男',
                    value: '男',
                },
                {
                    label:'女',
                    value: '女',
                }
            ],
            gender: '',
            //预约状态下拉框
            selectStation: [
                {
                    label:'禁止',
                    value: '禁止',
                }, {
                    label:'启用',
                    value: '启用',
                }
            ],
            station: '',
        },
        created() {
            this.findPage();
        },
        methods: {
            resetForm() {
                this.activeName = 'first';
                this.formData = {};
                this.roleIds = [];
            },

            //分页查询
            findPage() {
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString,
                }
                axios.post("/user/findPage.do", param,).then((response) => {
                    this.dataList = response.data.data.rows;
                    this.pagination.total = response.data.data.total;
                });
            },

            //弹出新增用户框并显示角色列表
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
                this.tableData=this.dataList.roles;
                axios.post("/role/findAll.do").then((response) => {
                    if (response.data.flag) {
                        this.tableData = response.data.data;
                    } else {
                        this.$message.error(response.data.message);
                    }
                });
            },

            //提交用户信息，添加用户
            handleAdd() {
                this.$refs["dataAddForm"].validate((valid) => {
                    if (valid) {
                        this.formData.station=this.station;
                        this.formData.gender=this.gender;
                        axios.post("/user/add.do?roleIds=" + this.roleIds, this.formData).then((response) => {
                            if (response.data.flag) {
                                this.$message({
                                    type: 'success',
                                    message: response.data.message
                                });
                            } else {
                                this.$message.error(response.data.message);
                            }
                        }).finally(() => {
                            this.dialogFormVisible = false;
                            this.findPage();
                        });
                    } else {
                        this.$message.error("请正确填写用户信息");
                    }
                });

            },

            //页码更新分页查询
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            //弹出编辑框
            handleEditUser(row) {
                this.activeName = 'first',
                axios.post("/role/findAll.do" ).then((response) => {
                    if (response.data.flag) {
                        this.tableData = response.data.data;
                        this.editDialogFormVisible = true;
                    } else {
                        this.$message.error("获取数据失败，请刷新页面重试");
                    }
                });

                axios.post("/user/findUserInfo.do?id="+row.id).then((response)=>{
                    this.formData=response.data.data;
                    this.gender=this.formData.gender;
                    this.station=this.formData.station;
                    var roles=response.data.data.roles;
                    if(roles.length>0){
                        for (var i=0;i<roles.length;i++){
                           this.roleIds.push( roles[i].id);
                        }
                    }

                });
            },

            //提交编辑后的用户信息进行更新
            handleUpdate() {
                this.$refs['dataEditForm'].validate((valid) => {
                    if (valid) {
                        this.formData.roleIds=this.roleIds;
                        axios.post("/user/update.do" ,this.formData).then((response) => {
                            if (response.data.flag) {
                                this.$message({
                                    type: 'success',
                                    message: response.data.message
                                });
                                this.findPage();
                                this.editDialogFormVisible = false;
                            } else {
                                this.$message.error(response.data.message);
                            }
                        });
                    } else {
                        this.$message.error("请正确填写用户信息");
                    }
                });
            },

            //删除预约
            handleDelete(row) {
                this.$confirm("确认删除此用户吗？", "提示", {type: 'warning'}).then(() => {
                    axios.post("/user/delete.do?id=" + row.id).then((reponse) => {
                        if (reponse.data.flag) {
                            this.$message({
                                type: 'success',
                                message: reponse.data.message
                            });
                            this.findPage();
                        } else {
                            this.$message.error(response.data.message);
                        }
                    });
                });
            },

            changeStatus(row) {
                var param = {
                    id: row.id,
                    orderStatus: row.orderStatus,
                };
                axios.post("/order/changeOrderStatus.do", param).then((response) => {
                    if (!response.data.flag) {
                        this.$message.error(response.data.message);
                    }
                });

            }
        },


    })

</script>
</html>
